package com.frank.oj.service.oj.impl;

import com.baomidou.mybatisplus.core.metadata.IPage;
import com.frank.oj.common.exception.StatusFailException;
import com.frank.oj.common.exception.StatusForbiddenException;
import com.frank.oj.common.exception.StatusNotFoundException;
import com.frank.oj.common.result.CommonResult;
import com.frank.oj.common.result.ResultStatus;
import com.frank.oj.manager.ContestScoreBoardManager;
import com.frank.oj.model.dto.ContestRankDTO;
import com.frank.oj.model.vo.ContestOutsideInfoVO;
import com.frank.oj.service.oj.ContestScoreBoardService;
import org.springframework.stereotype.Service;

import javax.annotation.Resource;

/**
 * @author frank
 * @Date 2024/4/22
 */
@Service
public class ContestScoreBoardServiceImpl implements ContestScoreBoardService {
    @Resource
    private ContestScoreBoardManager contestScoreBoardManager;
    @Override
    public CommonResult<ContestOutsideInfoVO> getContestOutsideInfo(Long cid) {
        try {
            return CommonResult.successResponse(contestScoreBoardManager.getContestOutsideInfo(cid));
        } catch (StatusNotFoundException e) {
            return CommonResult.errorResponse(e.getMessage(), ResultStatus.NOT_FOUND);
        } catch (StatusForbiddenException e) {
            return CommonResult.errorResponse(e.getMessage(), ResultStatus.FORBIDDEN);
        }
    }

    @Override
    public CommonResult<IPage> getContestOutsideScoreboard(ContestRankDTO contestRankDto) {
        try {
            return CommonResult.successResponse(contestScoreBoardManager.getContestOutsideScoreboard(contestRankDto));
        }  catch (StatusForbiddenException e) {
            return CommonResult.errorResponse(e.getMessage(), ResultStatus.FORBIDDEN);
        } catch (StatusFailException e) {
            return CommonResult.errorResponse(e.getMessage());
        }
    }
}
